package core.util;

import java.util.Calendar;
import java.util.Hashtable;

/**
 * @author songduk park
 * 
 */
public class CalendarUtil {

	static final Hashtable<Integer, String> months = new Hashtable<Integer, String>();
	{
		months.put(1, "Jan");
		months.put(2, "Feb");
		months.put(3, "Mar");
		months.put(4, "Apr");
		months.put(5, "May");
		months.put(6, "Jun");
		
		months.put(7, "Jul");
		months.put(8, "Aug");
		months.put(9, "Sep");
		months.put(10, "Oct");
		months.put(11, "Nov");
		months.put(12, "Dec");
	}

	public String yyyymmdd() {
		Calendar cal = Calendar.getInstance();

		int init_year = cal.get(Calendar.YEAR);
		int init_month = cal.get(Calendar.MONTH) + 1;
		int init_day = cal.get(Calendar.DATE);

		return init_year + "-" + addZero(init_month) + "-" + addZero(init_day);
	}

	public String getMonthName(int index) {
		return months.get(index);
	}

	public String yyyymmddAMonthBefore() {
		Calendar cal = Calendar.getInstance();

		cal.add(Calendar.MONTH, -1);
		int init_year = cal.get(Calendar.YEAR);
		int init_month = cal.get(Calendar.MONTH) + 1;
		int init_day = cal.get(Calendar.DATE);

		return init_year + "-" + addZero(init_month) + "-" + addZero(init_day);
	}

	public String addZero(int i) {
		if (i < 10)
			return "0" + i;
		else
			return "" + i;
	}

}
